﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using Accountant.ViewModels;
using Caliburn.Micro;
using System.Linq;

namespace Accountant.DataModel
{
  partial class Account : PropertyChangedBase
  {
    public override string ToString()
    {
      return string.Format("{0}: {1}", Id, Name);
    }

    #region ' IsSelected '

    private bool _isSelected;

    [NotMapped]
    public bool IsSelected
    {
      get { return _isSelected; }
      set
      {
        if (value.Equals(_isSelected)) return;
        _isSelected = value;
        NotifyOfPropertyChange(() => IsSelected);
        if (_isSelected)
        {
          IoC.Get<ShellViewModel>().SelectedAccount = this;
        }
      }
    }

    #endregion

    [NotMapped]
    public IEnumerable<Account> DerivedVisible { get { return DerivedAccounts.Where(acc => !acc.IsHidden); } }

/*
    [EditorBrowsable(EditorBrowsableState.Never)]
    public void AbsorbGraphIntoContext(AccountantContext context, HashSet<object> visited)
    {
      if (!visited.Add(this)) return;
      Id = context.Accounts.Count;
      context.Accounts.Add(this);
      if (_DerivedAccounts != null)
        foreach (var item in _DerivedAccounts)
          item.AbsorbGraphIntoContext(_context, visited);

      if (BaseAccount != null)
        BaseAccount.AbsorbGraphIntoContext(_context, visited);
    }*/
  }
}